/*
 * @Author: yushuang
 * @Date: 2024-12-17 17:46:48
 * @LastEditors: yushuang
 * @LastEditTime: 2024-12-17 17:47:26
 * @Description:
 */
import { computed } from 'vue';
import { toArray } from '@v-c/utils';
import { useUserStore } from '@/stores/user';
import type { AccessEnum } from '@/utils/constant';

export function useAccess() {
  const userStore = useUserStore();
  const roles = computed(() => userStore.roles);
  const hasAccess = (roles: (string | number)[] | string | number | AccessEnum) => {
    const accessRoles = userStore.roles;
    const roleArr = toArray(roles).flat(1);
    return roleArr.some(role => accessRoles?.includes(role));
  };
  return {
    hasAccess,
    roles
  };
}
